#include <iostream>
#include "command_manager.h"

// CmdArgs

CmdArgs::CmdArgs(std::list<std::string>* _args)
	: IArgs(), Args(_args)
{
}

CmdArgs::~CmdArgs()
{
}

// CmdMngrArgs

CmdMngrArgs::CmdMngrArgs(std::string const& _name, CmdArgs* _params)
	: IArgs(), Name(_name), Params(_params)
{
}

CmdMngrArgs::~CmdMngrArgs()
{
}

CommandManager::CommandManager()
	: AManager<Command>()
{
}

// CommandManager

CommandManager::~CommandManager()
{
}

void CommandManager::Manage(IArgs* _args)
{
	CmdMngrArgs* args = dynamic_cast<CmdMngrArgs*>(_args);
	if (_args == NULL)
		return ;
	Elements::iterator it = m_elements.begin();
	for (; it != m_elements.end(); it++)
	{
		if (it->second.first->Object != NULL)
		{
			if (args->Name == it->second.first->Object->GetName())
			{
				if (it->second.second != NULL)
				{
					it->second.second(it->second.first, args->Params);
					std::cout << "Done." << std::endl << std::endl;
					return ;
				}
			}
		}
	}
	std::cout << args->Name << ": Command not found." << std::endl;
}